import { Window_Selectable } from "@/windows/Window_Selectable.js";
import { TextManager } from "@/managers/TextManager.js";

export class Window_EquipCommand extends Window_Selectable {
    constructor(width, height) {
        super(width, height, false);
        this.init(width, height);
    }

    init(width, height) {
        this._list = [
            { name: TextManager.equip2, callback: null },
            { name: TextManager.optimize, callback: null },
            { name: TextManager.clear, callback: null }
        ];
        this.cancelHandler = null;
        super.init(width, height);
    }

    destroy(opts){
        super.destroy(opts);
        this.cancelHandler=null;
    }

    row() { return 1; }
    viewRow() { return 1; }
    column() { return this.length(); }
    viewColumn() { return this.length(); }
    length() { return this._list.length; }

    itemWidth() { return this.contentsWidth() / this.viewColumn(); }

    setHandler(name, callback) {
        if (name == 'cancel') {
            this.cancelHandler = callback;
        } else {
            let item = this._list.find(item => item.name == name);
            if (item) {
                item.callback = callback;
            }
        }
    }

    drawItem(index, x, y, width, height) {
        let item = this._list[index];
        if (item) {
            this.drawText(item.name, x, y, width, height, 'center');
        }
    }

    onResponse(index) {
        this._list[index]?.callback?.(index);
    }

    onCancel(){
        this.cancelHandler?.();
    }
}